﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using InternalManagementSystem.DAO;
using InternalManagementSystem.DAO.Models;

/// <summary>
///AdminBLL 的摘要说明
/// </summary>
public class AdminBLL
{
    Permission permission = null;

    public AdminBLL()
    {
        //
        //TODO: 在此处添加构造函数逻辑
        //
     
    }

    public AdminBLL(Permission permission)
	{
		//
		//TODO: 在此处添加构造函数逻辑
		//
        this.permission = permission;
	}

    #region 编辑用户类别


    /// <summary>
    /// 获取用户类别
    /// </summary>
    /// <param name="UserTypeid"></param>
    /// <returns></returns>
    public UserType GetUserType(int UserTypeid)
    {
       
            UserTypeDAO dao = new UserTypeDAO();
            return dao.LoadUserType(UserTypeid);
        
    }

    /// <summary>
    /// 获取所有用户类别
    /// </summary>
    /// <returns></returns>
    public IList<UserType> GetAllUserType()
    {
        UserTypeDAO dao = new UserTypeDAO();
        return dao.LoadAllUserTypes().Cast<UserType>().ToList();
    }

    /// <summary>
    /// 新增用户类别
    /// </summary>
    /// <param name="UserType"></param>
    /// <returns></returns>
    public bool AddUserType(UserType UserType)
    {
        bool result = false;
        if (permission.IsUserTypeEdit)
        {
            try
            {
                UserTypeDAO dao = new UserTypeDAO();
                dao.InsertUserType(UserType);
                result = true;
            }
            catch
            {
                
            }
        }

        return result;
    }

    /// <summary>
    /// 更新用户类别
    /// </summary>
    /// <param name="UserType"></param>
    /// <returns></returns>
    public bool UpdateUserType(UserType UserType)
    {
        bool result = false; 
        if (permission.IsUserTypeEdit)
        {
            try
            {
                UserTypeDAO dao = new UserTypeDAO();
                dao.UpdateUserType(UserType);
                result = true;
            }
            catch
            {
                 
            }
        }

        return result;
    }

    /// <summary>
    /// 删除用户类别
    /// </summary>
    /// <param name="UserTypeid"></param>
    /// <returns></returns>
    public bool DeleteUserType(int UserTypeid)
    {
         bool result = false;
         if (permission.IsUserTypeEdit)
         {
             try
             {
                 UserTypeDAO dao = new UserTypeDAO();
                 dao.DeleteUserType(UserTypeid);
                 result = true;
             }
             catch
             {
             }
         }

        return result;
    }



    #endregion

    #region 编辑用户角色

    /// <summary>
    /// 获取用户类别
    /// </summary>
    /// <param name="UserTypeid"></param>
    /// <returns></returns>
    public UserRole GetUserRole(int UserRoleid)
    {

        UserRoleDAO dao = new UserRoleDAO();
        return dao.LoadUserRole(UserRoleid);

    }

    /// <summary>
    /// 获取所有用户类别
    /// </summary>
    /// <returns></returns>
    public IList<UserRole> GetAllUserRole()
    {
        UserRoleDAO dao = new UserRoleDAO();
        return dao.LoadAllUserRoles().Cast<UserRole>().ToList();
    }

    /// <summary>
    /// 新增用户类别
    /// </summary>
    /// <param name="UserType"></param>
    /// <returns></returns>
    public bool AddUserRole(UserRole UserRole)
    {
        bool result = false;
        if (permission.IsUserRoleEdit)
        {
            try
            {
                UserRoleDAO dao = new UserRoleDAO();
                dao.InsertUserRole(UserRole);
                result = true;
            }
            catch
            {

            }
        }

        return result;
    }

    /// <summary>
    /// 更新用户类别
    /// </summary>
    /// <param name="UserType"></param>
    /// <returns></returns>
    public bool UpdateUserRole(UserRole UserRole)
    {
        bool result = false;
        if (permission.IsUserRoleEdit)
        {
            try
            {
                UserRoleDAO dao = new UserRoleDAO();
                dao.UpdateUserRole(UserRole);
                result = true;
            }
            catch
            {

            }
        }

        return result;
    }

    /// <summary>
    /// 删除用户类别
    /// </summary>
    /// <param name="UserTypeid"></param>
    /// <returns></returns>
    public bool DeleteUserRole(int UserRoleid)
    {
        bool result = false;
        if (permission.IsUserRoleEdit)
        {
            try
            {
                UserRoleDAO dao = new UserRoleDAO();
                dao.DeleteUserRole(UserRoleid);
                result = true;
            }
            catch
            {
            }
        }

        return result;
    }

    #endregion

    #region 给班组安全员分配公司

    //需要创建一张管理表
    //对于本公司的用户 companyid为0;

    #endregion
}
